package com.hmall.gateway.filter;

import lombok.Data;
import org.springframework.cloud.gateway.filter.GatewayFilter;
import org.springframework.cloud.gateway.filter.GatewayFilterChain;
import org.springframework.cloud.gateway.filter.factory.AbstractGatewayFilterFactory;
import org.springframework.http.server.reactive.ServerHttpResponse;
import org.springframework.stereotype.Component;
import org.springframework.web.server.ServerWebExchange;
import reactor.core.publisher.Mono;

import java.io.ObjectInputFilter;
import java.util.List;

@Component
public class PrintAnyGatewayFilterFactory extends AbstractGatewayFilterFactory<PrintAnyGatewayFilterFactory.Config> {
    @Override
    public GatewayFilter apply(Config config) {
        return new GatewayFilter() {
            @Override
            public Mono<Void> filter(ServerWebExchange exchange, GatewayFilterChain chain) {
                System.out.println("PrintAny filter 执行了");
                return chain.filter(exchange);
            }
        };

    }


    @Data
    public static class Config {
        private String name;
        private boolean city;
        private boolean sex;
    }
    @Override
    public List< String> shortcutFieldOrder(){
        return List.of("name","city","sex");
    }
    public PrintAnyGatewayFilterFactory() {
        super(Config.class);
    }
//    @Override
//    public GatewayFilter apply(Object config) {
//        return new GatewayFilter() {
//            @Override
//            public Mono<Void> filter(ServerWebExchange exchange, GatewayFilterChain chain) {
//                ServerHttpResponse response = exchange.getResponse();
////        response.setRawStatusCode(401);
////        return response.setComplete();
//                System.out.println("路由过滤器，放行");
//                return chain.filter(exchange);
//
//            }
//        };
//    }
}
